﻿Imports System.Data.OleDb
Public Class profile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.Params("DieterName") = User.Identity.Name Then
            Button5.Visible = True
        Else
            Button5.Visible = False
            StartingWeight_LBL.Visible = False
            TargetWeight_LBL.Visible = False
            Label5.Visible = False
            Label6.Visible = False
        End If
        '**here goes - this section is supposed to fill the label/s**'
        Dim rdrSql As OleDbDataReader = DirectCast(SqlDataSource2.Select(DataSourceSelectArguments.Empty), OleDbDataReader)

        While rdrSql.Read()

            Dim christian As String
            Dim surname As String
            christian = rdrSql("firstName").ToString()
            surname = rdrSql("lastName").ToString()
            User_LBL.Text = christian + " " + surname
            Age_LBL.Text = rdrSql("Age").ToString()
            ProfileDesc_LBL.Text = rdrSql("Description").ToString()
            StartingWeight_LBL.Text = rdrSql("StartingWeight").ToString()
            TargetWeight_LBL.Text = rdrSql("TargetWeight").ToString()

        End While
        rdrSql.Close()
    End Sub

    Protected Sub SqlDataSource2_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs)

        Dim thisMember As String
        thisMember = Convert.ToString(Context.Request.QueryString("DieterName"))
        e.Command.Parameters("DieterName").Value = thisMember

    End Sub

    Protected Function GetMemberImagePath() As String
        '** this section locates the image file path from the database so that the image can be show outside of gridview**'

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim value As String
        value = Convert.ToString(Context.Request.QueryString("DieterName"))
        value = value + "'"
        Dim SqlString As String = "SELECT ProfilePicture from Profile WHERE DieterName='" & value
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)

        oleDbConn.Open()
        Dim imagepath = cmd.ExecuteScalar()

        If String.IsNullOrEmpty(ImagePath) Then
            ImagePath = "insertdefaultimagepath"
        End If

        Return ImagePath

    End Function

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim dateString As String
        dateString = Date.Now.ToString("dd/MM/yyyy")
        Dim weightSql As String = "INSERT INTO weights(Member, Weight, Posted) Values (@f1,@f2,@f3)"
        Dim weightcmd As OleDbCommand = New OleDbCommand(weightSql, oleDbConn)
        weightcmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        weightcmd.Parameters.AddWithValue("@f2", TextBox1.Text)
        weightcmd.Parameters.AddWithValue("@f3", dateString)
        oleDbConn.Open()
        weightcmd.ExecuteNonQuery()
        Label2.Text = "Thank You"

    End Sub

   
End Class